<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家账户绑定控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajucompanymasterController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete',
			'foreverdelete_deep',
			'input_change_ajax',
			'input_change_unique',
			'forbid',
			'closeitem',
			'openitem',
			'resume',
			'clear_recycle',
			'save_sort',
			'insert',
			'add',
			'edit',
			'update'
		);
		
		parent::init__();
	}
	
	public function index($sName=null,$bDisplay=true){
		$arrCompanyVerify=Model::F_('jiajucompanyverify')->where(array('jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))->getOne();

		$this->assign('arrCompanyVerify',$arrCompanyVerify);
		$this->display();
	}

	public function master(){
		// 更新绑定帐号信息
		if($this->isPost()){
			$oJiajucompanymaster=JiajucompanymasterModel::F('jiajucompany_id=?',$GLOBALS['_company_']['jiajucompany_id'])->getOne();
			$oJiajucompanymaster->save('update');
			if($oJiajucompanymaster->isError()){
				$this->E($oJiajucompanymaster->getErrorMessage());
			}else{
				$this->S('商家帐号绑定信息保存成功');
			}
		}
		
		$this->display();
	}

	public function verify(){
		$oCompanyVerify=JiajucompanyverifyModel::F()->where(array('jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))->getOne();

		// 读取当前的认证图片
		$arrVerifyImg=Model::F_('jiajucompanyverifyimg','jiajucompany_id=?',$GLOBALS['_company_']['jiajucompany_id'])->getAll();
		$this->assign('arrVerifyImg',$arrVerifyImg);

		// 更新工商注册信息
		if($this->isPost()){
			$oCompanyVerify->save('update');
			if($oCompanyVerify->isError()){
				$this->E($oCompanyVerify->getErrorMessage());
			}else{
				// 清理工商认证信息
				Model::M_('jiajucompanyverifyimg')->deleteWhere(array('jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']));

				if(!empty($_POST['jiajucompanyverifyimg'])){
					foreach($_POST['jiajucompanyverifyimg'] as $sValue){
						if($sValue){
							Model::M_('jiajucompanyverifyimg')->insertWhere(
								array(
									'jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id'],
									'jiajucompanyverifyimg_file'=>$sValue,
									'create_dateline'=>time()
								)
							);
						}
					}
				}
				
				$this->S('商家工商注册信息保存成功');
			}
		}

		$this->assign('oValue',$oCompanyVerify);
		$this->display();
	}

}
